package com.jerry.mingxing.ui.fashion;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.jerry.mingxing.R;
import com.jerry.mingxing.ui.fashionfocus.FashionFocusFragment;
import com.jerry.mingxing.ui.fashionnew.FashionNewFragment;
import com.jerry.mingxing.ui.fashionrecommend.FashionRecommendFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/8/29.
 */
public class FashionFragment extends Fragment {

    ViewPager getFashionFramelayout;
    @Bind(R.id.fashion_button_)
    Button fashionButton;
    @Bind(R.id.fashion_tab)
    TabLayout fashionTab;
    @Bind(R.id.fashion_button_1)
    Button fashionButton1;
    @Bind(R.id.fashion_framelayout)
    ViewPager fashionFramelayout;
    private Activity activity;
    private Context context;
    private View view;
    private FragmentManager manager = null;
    private String[] arrTabTitle;
    private List<Fragment> fragmentlist = new ArrayList<>();
    private FashionAdapter fashionAdapter;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();
        context = getContext();

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fashionfragment, container, false);
        ButterKnife.bind(this, view);

        initDate();
        return view;
    }

    private void initDate() {
        FashionFocusFragment fashionFocusFragment = new FashionFocusFragment();
        FashionNewFragment fashionNewFragment = new FashionNewFragment();
        FashionRecommendFragment fashionRecommendFragment = new FashionRecommendFragment();
        fragmentlist.add(fashionFocusFragment);
        fragmentlist.add(fashionRecommendFragment);
        fragmentlist.add(fashionNewFragment);
        arrTabTitle = getResources().getStringArray(R.array.fashionfragment_title);
        fashionTab.setTabMode(fashionTab.MODE_FIXED);
        fashionTab.addTab(fashionTab.newTab().setText(arrTabTitle[0]));
        fashionTab.addTab(fashionTab.newTab().setText(arrTabTitle[1]));
        fashionTab.addTab(fashionTab.newTab().setText(arrTabTitle[2]));
        fashionAdapter = new FashionAdapter(getActivity().getSupportFragmentManager(), fragmentlist, arrTabTitle);
        fashionFramelayout.setAdapter(fashionAdapter);
        fashionTab.setupWithViewPager(fashionFramelayout);

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


}
